package com.ruoyi.machine.base.accessory.service;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.machine.base.accessory.domain.Accessory;
import com.ruoyi.machine.base.accessory.mapper.AccessoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备附件信息
 * 业务层处理
 */
@Service
public class AccessoryServiceImpl implements IAccessoryService{

    @Autowired
    private AccessoryMapper accessoryMapper;

    /**
     * 查找附属设备清单
     * @param accessory
     * @return
     */
    @Override
    public List<Accessory> selectAccessoryList(Accessory accessory) {
        return accessoryMapper.selectAccessoryList(accessory);
    }

    /**
     * 根据Id查找附属设备
     * @param accessoryId
     * @return
     */
    @Override
    public Accessory selectAccessoryById(String accessoryId) {
        return accessoryMapper.selectAccessoryById(accessoryId);
    }

    /**
     * 添加附属设备
     * @param accessory
     * @return
     */
    @Override
    public int insertAccessory(Accessory accessory) {
        if (StringUtils.isNotNull(accessoryMapper.selectAccessoryById(accessory.getAccessoryId()))) {
            //存在
            return 0;
        }
        //不存在
        return accessoryMapper.insertAccessory(accessory);
    }

    /**
     * 更新附属设备
     * @param accessory
     * @return
     */
    @Override
    public int updateAccessory(Accessory accessory) {
        if (!StringUtils.isNotNull(accessoryMapper.selectAccessoryById(accessory.getAccessoryId()))) {
            //不存在
            return 0;
        }
        return accessoryMapper.updateAccessory(accessory);
    }

    /**
     * 删除附属设备
     * @param accessory
     * @return
     */
    @Override
    public int deleteAccessory(Accessory accessory) {
        return accessoryMapper.deleteAccessory(accessory);
    }
}
